<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 11065
  Date: 2021/10/29
  Time: 23:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <div class="bck"></div>
    <style>
        .bck::after {
            content: "";
            background: url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201412%2F08%2F20141208143337_LLjBY.thumb.400_0.gif&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638426906&t=eff912ca68f1898d1bde46383405bb68);
            opacity: 0.65;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            background-size: cover;
            position: absolute;
            z-index: -1;
        }
    </style>
    <title>12306余票查询系统</title>
</head>
<body align="center">
    <h1 align="center">12306余票查询</h1>
    <div style="margin-top: 18%; margin-left: 5%">
        <div style="font-size: 18px; font-weight: 550;">
            手机号：<input name="phone" id="phone" type="text" placeholder="电话号码">
        </div>
        <div style="margin-top: 1%; font-size: 18px; font-weight: 550">
            密码：<input name="password" id="password" type="password" placeholder="密码">
        </div>
        <div style="margin-top: 1%">
            <button type="button" onclick="login()">登录</button>
        </div>
    </div>
</body>

<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.4.1.min.js"></script>
<script type="text/javascript" language="JavaScript"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.4.1.min.js"></script>
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="/js/plugins/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script src="/js/plugins/bootstrapValidator/bootstrapValidator.min.js"></script>
<script>
    function login() {
        var password = $("#password").val();
        var phone = $("#phone").val();
        var 乘客 = {};
        乘客.手机号 = phone;
        乘客.密码 = password;
        $.ajax({
            type: 'post',
            url: '/login',
            contentType: "application/json; charset=UTF-8",
            data: JSON.stringify(乘客),
            dataType: 'json',
            success:function(data) {
                if(data.code == 200){
                    alert("登录成功")
                    if (data.data.权限 == '管理员'){
                        window.location.href = "Order"
                    }else {
                        window.location.href = "Ticket"
                    }
                }
                else{
                    alert("用户名或密码错误");
                    location.reload();
                }
            }
        });
    }
</script>
</html>